package com.fyzk.activity.lottery.zc_new.adapter;


import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.fyzk.bean.ZCGameQueueItem;
import com.fyzk.interfaces.OnBetCheckedListener;
import com.tyjc.lottery.R;

import java.util.ArrayList;
import java.util.List;

public abstract class ZCBaseAdapter extends BaseAdapter{
	protected Context context;
	private List<ZCGameQueueItem> infors = new ArrayList<>();
	private OnBetCheckedListener listener;
	
	public ZCBaseAdapter(Context context, List<ZCGameQueueItem> infors){
		this.context = context;
		if (infors != null) {
			this.infors = infors;
		}
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return infors.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return infors.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		ZCGameQueueItem data = infors.get(position);
		ViewHolder  holder = null;
		if (convertView == null) {
			convertView = LayoutInflater.from(context).inflate(R.layout.zc_adapter_base, null);
			holder = new ViewHolder();
			holder.league_tv = (TextView) convertView.findViewById(R.id.zc_base_league);
			holder.teamId_tv = (TextView) convertView.findViewById(R.id.zc_base_teamid);
			holder.time_tv = (TextView) convertView.findViewById(R.id.zc_base_time);
			holder.right_ll = (LinearLayout) convertView.findViewById(R.id.zc_base_right);
			convertView.setTag(holder);
		}else{
			holder = (ViewHolder) convertView.getTag();
		}
		holder.league_tv.setText(data.getMatchName());
		holder.teamId_tv.setText(data.getMatchNum());
		String endTime = ""+data.getMatchDate();
		try {
			endTime = data.getMatchDate().substring(5, 16);
		} catch (Exception e) {
		}
		holder.time_tv.setText(endTime);
		holder.right_ll.removeAllViews();
		View view = getRightView(data, position);
		if (view != null) {
			holder.right_ll.addView(view);
		}
		return convertView;
	}
	
	protected abstract View getRightView(ZCGameQueueItem data, int position);
	
	protected void tongJi(){
		if (listener != null) {
			listener.onBetChecked();
		}
	}
	
	public void setOnZCTongJiListener(OnBetCheckedListener listener){
		this.listener = listener;
	}
	
	public void setList(List<ZCGameQueueItem> infors){
		if (infors != null) {
			this.infors = infors;
		}else{
			this.infors.clear();
		}
		this.notifyDataSetChanged();
	}
	
	private class ViewHolder{
		TextView league_tv;
		TextView teamId_tv;
		TextView time_tv;
		LinearLayout right_ll;
	}
	
	
	
	
	
	

}
